package com.polymer.app.utils;

import java.awt.geom.Point2D;

public class MathUtils {

    /**
     * 
         * @功能: 根据经纬度计算直线距离,单位千米
         * @参数: @return
         * @返回类型： Boolean
         * @exception
         * @since  1.0.0
     */
    public static double caculateDistance(Point2D pointA, Point2D pointB) {
        double dis = Math.round(
                6371.393 * 2
                        * Math.asin(
                                Math.sqrt(
                                        Math.pow(Math.sin((pointA.getX() * Math.PI / 180 - pointB.getX() * Math.PI / 180) / 2), 2.0)
                                                + Math.cos(pointA.getX() * Math.PI / 180) * Math.cos(pointB.getX() * Math.PI / 180)
                                                        * Math.pow(Math.sin((pointA.getY() * Math.PI / 180 - pointB.getY() * Math.PI / 180) / 2), 2.0)))
                        * 1000 * 1)
                / 1000;
        return dis;
    }
    
    public static void main(String[] args) {
        Point2D p1 = new Point2D.Double(130.0, 30.0);
        Point2D p2 = new Point2D.Double(113.1, 22.1);
        System.out.println(caculateDistance(p1, p2));
    }
}
